import baseUrl from '@/utils/baseUrlShop.js'
// 图片上传
module.exports = {
	upload() {
		var that = this;
		return new Promise((resolve, reject) => {
			uni.chooseImage({
				count: 1,
				success: (resp) => {
					const {
						tempFilePaths
					} = resp;
					console.log("选择图片路径", tempFilePaths);
					uni.uploadFile({
						// url: "https://www.ziyoupin.cn/api/common/upload",
						url: `${baseUrl}/common/upload`,
						filePath: tempFilePaths[0],
						name: 'file',
						success: (resp) => {
							let tmpData = JSON.parse(resp.data)
							console.log("文件上传", tmpData);
							resolve(tmpData);
						},
						fail: error => {
							console.log('出错啦', error)
							reject(error)
						}
					});
				},
			});
		});
	},
	uploadFile(path){
		return new Promise((resolve, reject)=>{
			uni.uploadFile({
				// url: "https://www.ziyoupin.cn/api/common/upload",
				url: `${baseUrl}/Ajax/upload`,
				filePath: path,
				name: 'file',
				success: (resp) => {
					let tmpData = JSON.parse(resp.data)
					console.log("文件上传", tmpData);
					resolve(tmpData);
				},
				fail: error => {
					console.log('出错啦', error)
					reject(error)
				}
			});
		})
	},
	uploadStore() {
		var that = this;
		return new Promise((resolve, reject) => {
			uni.chooseImage({
				count: 1,
				success: (resp) => {
					const {
						tempFilePaths
					} = resp;
					console.log("选择图片路径", tempFilePaths);
					uni.uploadFile({
						// url: "https://www.ziyoupin.cn/api/common/upload",
						url: `${baseUrl}/Ajax/upload`,
						filePath: tempFilePaths[0],
						name: 'file',
						success: (resp) => {
							let tmpData = JSON.parse(resp.data)
							console.log("文件上传", tmpData);
							resolve(tmpData.data);
						},
						fail: error => {
							console.log('出错啦', error)
							reject(error)
						}
					});
				},
			});
		});
	},
};
